package com.sun.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sun.dto.DrugDto;
import com.sun.entity.Category;
import com.sun.entity.Drug;
import com.sun.mapper.DrugMapper;
import com.sun.mapper.StoreMapper;
import com.sun.service.DrugService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Project: hospitalDrugInformationManagement
 * @Author: 86178
 * @Date: 2023/2/21 17:06
 * @FileName: DrugServiceImpl
 * @Description: ""
 */
@Service
public class DrugServiceImpl extends ServiceImpl<DrugMapper, Drug> implements DrugService {

    @Autowired
    private DrugMapper drugMapper;
    @Autowired
    private StoreMapper storeMapper;

    @Override
    public List<DrugDto> selectAll() {
        List<DrugDto> drugDtos = drugMapper.selectAll();
        return drugDtos;
    }

    @Override
    public void selectDrug() {
        int countDrug = drugMapper.countDrug();
        System.out.println(countDrug);
        List<Category> categories = drugMapper.countByCategoryId();
        System.out.println(categories.toString());
        int countStore = storeMapper.countStore();
        System.out.println(countStore);
        List<Category> categories1 = storeMapper.countByCategory();
        categories1.forEach(it -> {
            if (it.getCategoryNum() == null) {
                it.setCategoryNum(0);
            }
        });
        System.out.println(categories1.toString());
    }


}
